home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_80 / playall.pas < prev    next >
Pascal/Delphi Source File  |  1995-01-01  |  2KB  |  95 lines

  1. unit PlayInfo;
  2.  
  3. interface
  4. uses
  5.   Strings,
  6.   MMSystem,
  7.   WinProcs,
  8.   WinTypes;
  9.  
  10. const
  11.   MsgLen = 200;
  12.  
  13. var
  14.   wDeviceID: Word;
  15.  
  16. function ErrorMsg(Error: LongInt; Msg: PChar): Boolean; export;
  17. function OpenWave(FileName: Pchar): Boolean; export;
  18. function PlayWave: Boolean; export;
  19. function CloseWave: Boolean; export;
  20.  
  21. implementation
  22.  
  23. function GetErrorMessage(RC:LongInt; S: PChar): PChar;
  24. begin
  25.   if not mciGetErrorString(RC, S, MsgLen) then
  26.     StrCopy(S, 'No message available');
  27.   GetErrorMessage := S;
  28. end;
  29.  
  30. function ErrorMsg(Error: LongInt; Msg: PChar): Boolean;
  31. var
  32.   S, S1: array[0..MsgLen] of Char;
  33. begin
  34.   ErrorMsg := True;
  35.   StrCopy(S, 'Return Code: ');
  36.   Str(Error:5, S1);
  37.   StrCat(S, S1);
  38.   StrCat(S, Msg);
  39.   StrCat(S, GetErrorMessage(Error, S1));
  40.   if Error <> 0 then begin
  41.     MessageBox(0, S1, 'Information', mb_OK);
  42.     ErrorMsg := False;
  43.   end;
  44. end;
  45.  
  46. function OpenWave(FileName: Pchar): Boolean;
  47. var
  48.   OpenParms: TMci_Open_Parms;
  49.   Style: LongInt;
  50.   Result: LongInt;
  51.   S1: array [0..MsgLen] of Char;
  52. begin
  53.   OpenWave := True;
  54.   OpenParms.lpstrDeviceType := 'WaveAudio';
  55.   OpenParms.lpstrElementName := FileName;
  56.   Style := Mci_Open_Type or Mci_Open_Element;
  57.   Result := MciSendCommand(0, MCI_OPEN, Style, LongInt(@OpenParms));
  58.   if Result <> 0 then begin
  59.     OpenWave := False;
  60.     ErrorMsg(Result, S1);
  61.     exit;
  62.   end;
  63.   wDeviceId := OpenParms.wDeviceID;
  64. end;
  65.  
  66.  
  67. function CloseWave: Boolean;
  68. var
  69.   Result: LongInt;
  70.   S1: array[0..MsgLen] of Char;
  71. begin
  72.   CloseWave := True;
  73.   Result := mciSendCommand(wDeviceID, MCI_Close, 0, 0);
  74.   if Result <> 0 then begin
  75.     CloseWave := False;
  76.     ErrorMsg(Result, S1);
  77.     exit;
  78.   end;
  79. end;
  80.  
  81. function PlayWave: Boolean;
  82. var
  83.   Result: LongInt;
  84.   PlayParms: TMci_Play_Parms;
  85.   S1: array[0..MsgLen] of Char;
  86. begin
  87.   PlayWave := True;
  88.   Result := MciSendCommand(wDeviceID, Mci_Play, Mci_Notify, LongInt(@PlayParms));
  89.   if Result <> 0 then begin
  90.     PlayWave := False;
  91.     ErrorMsg(Result, S1);
  92.     exit;
  93.   end;
  94. end;
  95. end.